package user;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public abstract class UserAction implements ActionListener
{
	private CurrentUser user;
	private int levelNeededToPerformAction;
	
	public UserAction(CurrentUser user, UserPrivilege privLevelNeeded)
	{
		this.user = user;
		this.levelNeededToPerformAction = privLevelNeeded.getLevel();
	}
	
	public UserAction(CurrentUser user, int levelNeededToPerformAction)
	{
		this.user = user;
		this.levelNeededToPerformAction = levelNeededToPerformAction;
	}
	
	@Override
	public void actionPerformed(ActionEvent e)
	{
		if (user.isRestricted(levelNeededToPerformAction))
			onRestricted( e );
		else
			onNotRestricted( e );
	}
	
	/**
	 * The code executed if the user is restricted
	 */
	public abstract void onRestricted(ActionEvent e);	
	/**
	 * The code executed if the user is NOT restricted
	 */
	public abstract void onNotRestricted(ActionEvent e);
}
